<?php
ob_start();
include("head_login.php");

$action = "";
if(isset($_GET["action"])) $action = $_GET["action"];

// login
if($action == "login") {

 $user = $_POST["user"];
 $pwd = sha1($user."$".$_POST["pwd"]); // username als salt verwenden

 $res = db_query("SELECT * FROM user WHERE name='".secure_mysql_string($user)."'");
 $v = mysql_fetch_array($res);
 if($v != null) {
  if($v["pwd"] == $pwd) {
   // login ok
   $_SESSION["user"] = $user;
   $uid = secure_get_unique_id();
   // save unique id to prevent session hijacking
   $_SESSION["uid"] = $uid;
   set_settings_user("uid", $uid);
  }
 }
 // go back to page
 if(isset($_GET["ref"])) header("Location: index.php?page=".secure_alphanum($_GET["ref"])); else header("Location: index.php");
}


// logout
if($action == "logout") {
 set_settings_user("uid", "");
 unset($_SESSION["user"]);
 ob_clean();
 header("Location: index.php");
 exit();
}

?>


<?php
include("footer.php");
?>

